<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   帮助指南
 */
defined('IN_YuLin') || exit('NO PERMIT!');

$table = Table('article');
if($a == 'list')
{
	$data  = [];
	$where = ' FROM '.$table.' t WHERE t.cid = 3 AND status = 1';

	$page = max(1,intval($_GET['page']));
	$size = max(1,intval($_GET['size']));

	$tmp = $db->getrow('SELECT COUNT(1) AS p '.$where);
	if($tmp['p'])
	{
		$limit = ' LIMIT '.($page - 1) * $size.','.$size;
		
		$data = $db->getall('SELECT t.* '.$where.$orderby.$limit);
		foreach($data as $key => $val)
		{
			$val['dateline'] = date('Y/m/d H:i:s',$val['dateline']);
			
			$data[$key] = $val;
		}
	}
	echo json_encode(['pageIndex'=>$page,'pageSize'=>$size,'total'=>intval($tmp['p']),'rows'=>$data]);
	exit;
	$head['title'] = '网站公告';
	
	$tpl->display('member/notice');
}

if ($a == 'more'){
    $id = $_REQUEST['id'];
    if (!$id){
        echo '参数丢失';
        return;
    }
    $infoSql     = 'SELECT * FROM ' . $table . ' WHERE id = ' . $id;
    $articleInfo['content'] = htmlspecialchars_decode($articleInfo['content']);
    $articleInfo = $db->getrow($infoSql);
    $tpl->display('member/notice_more');
}

if($a == 'index'){
    // 查询所有站内公告， 默认分类1
    $data  = array();
    $where = ' FROM '.$table.' t WHERE cid = 2';
    $order = ' ORDER BY id ASC';
    $limit = '';
    // 查询所有的新闻标题，左边展示
    $articleMenuData = $db->getall('SELECT id, title ' . $where . $order . $limit);
    $id    = $_GET['id'];
    if ($id){
        $where .= ' AND id = ' . $id;
    }else{
        $limit .= ' LIMIT 1';
    }
    $id         = $id ? $id : $articleMenuData[0]['id'];
    // 获取第一条信息
    $artInfo    = $db->getrow('SELECT * ' . $where . $order . $limit);
    $tpl->display('member/help_main');
}

